New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cl-component-translate

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cl-component-translate

Components for translating text, numbers, dates and times

  • 0.0.22
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

cl-component-translate

CrowdLab Translate Component

Components for translating text, numbers, dates and times.

Installation

$ npm install cl-component-translate

Components

Translation Provider

Wraps the tree to provide the context for translations, wrapper for react-intl's IntlProvider

Usage:

import { TranslationProvider } from 'crowdlab-react-translations';

const locale = {
  tag: 'en',
  language: 'en-GB',
  translations: {
    test: 'translated'
  }
};

<TranslationProvider locale={locale}>
  <div>Children</div>
</TranslationProvider>

Translate

Wrapper for react-intl's FormattedMessage, does the nuts and bolts of the translating.

Usage:

import { Translate } from 'crowdlab-react-translations';

<Translate id="key.to.translate" />

Number

Wrapper for react-intl's FormattedNumber

Usage:

import { Number } from 'crowdlab-react-translations';

<Number number="5" style="percent" />

Relative Date

Relative data formatting, ie. 5 minutes ago, In 4 years time etc.

Usage:

import { RelativeDate } from 'crowdlab-react-translations';

<RelativeDate date="1989-10-28T18:08:40+00:00" />

Timestamp

Timestamp date time formatting. ie: October 28, 1989, 4:25 PM

Usage:

import { Timestamp } from 'crowdlab-react-translations';

<Timestamp date="1989-10-28T18:08:40+00:00" />

Helper functions

injectTranslationHelpers

Wrapper for react-intl's injectIntl, provides a translate() method to wrapper component The translate() method works much the same as the Translate component

Usage:

import { injectTranslationHelpers } from 'crowdlab-react-translations';

const Component = (translate) => {
  const translatedThing = translate({ id: 'test.key' });

  return <div data-t={translatedThing} />;
}

export default injectTranslationHelpers()(Component);

injectTranslations

This is used for testing react components that need access to Translate. Because translate needs context to offer translations. This uses the default translations but you can pass custom translations as an additional argument.

Usage:

import { injectTranslations } from 'crowdlab-react-translations';

test('something is translated', (t) => {
  const translations = {
    test: 'translated text'
  };

  const wrapper = mount(injectTranslations(<Component />, translations));

  t.is(wrapper.text(), 'translated text');
})

FAQs

Package last updated on 12 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc